//
//  LZNoDataPublicView.m
//  laziz_Consumer
//
//  Created by xbnzd on 17/4/25.
//  Copyright © 2017年 XBN. All rights reserved.
//

#import "LZNoDataPublicView.h"
#import "Masonry.h"

@implementation LZNoDataPublicView

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    
    return self;
}

#pragma mark - show or hidden
+ (void)showNoDataViewInView:(UIView *)baseView
{
    if (baseView == nil) {
        return;
    }
    for (UIView *sub in baseView.subviews) {
        if ([sub isKindOfClass:[LZNoDataPublicView class]]) {
            return;
        }
    }
    
    LZNoDataPublicView *v = [[LZNoDataPublicView alloc] init];
    [v configureUI];
    v.backgroundColor = [UIColor clearColor];
    [baseView addSubview:v];
    
    [v mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(baseView).offset(-50);
        make.centerX.equalTo(baseView);
        make.size.mas_equalTo(CGSizeMake(280, 150));
    }];
}

+ (void)hiddenNoDataViewInView:(UIView *)baseView
{
    if (baseView == nil) {
        return;
    }
    for (UIView *sub in baseView.subviews) {
        if ([sub isKindOfClass:[LZNoDataPublicView class]]) {
            
            LZNoDataPublicView *v = (LZNoDataPublicView *)sub;
            [v removeFromSuperview];
        }
    }
}
#pragma mark - UI
- (void)configureUI
{
    UIImageView *icon = [[UIImageView alloc] init];
    icon.image = [UIImage imageNamed:@"no_data_public"];
    [self addSubview:icon];
    
    UILabel *l = [[UILabel alloc] init];
    l.textColor = UIColorFromRGB(0x999999, 1);
    l.font = [UIFont systemFontOfSize:13];
    l.textAlignment = NSTextAlignmentCenter;
    l.text = LZLocalizedString(@"refresh_footer_no_data", nil);
    [self addSubview:l];
    
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-38);
        make.size.mas_equalTo(CGSizeMake(70, 42));
    }];
    
    [l mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(icon.mas_bottom).offset(18);
        make.leading.and.trailing.mas_equalTo(0);
    }];
}

@end
